#!/usr/bin/env python
# vim:fileencoding=utf-8

from calibre.web.feeds.news import BasicNewsRecipe


class MoscowTimes(BasicNewsRecipe):
    title = 'The Moscow Times'
    __author__ = 'bugmen00t'
    description = '\u0410\u043D\u0433\u043B\u043E\u044F\u0437\u044B\u0447\u043D\u043E\u0435 \u0438\u0437\u0434\u0430\u043D\u0438\u0435 \u043E \u0420\u043E\u0441\u0441\u0438\u0438. \u041D\u0430\u0448\u0430 \u0440\u0435\u0434\u0430\u043A\u0446\u0438\u044F \u0434\u0435\u043B\u0438\u0442\u0441\u044F \u0441 \u0447\u0438\u0442\u0430\u0442\u0435\u043B\u044F\u043C\u0438 \u043F\u043E \u0432\u0441\u0435\u043C\u0443 \u043C\u0438\u0440\u0443 \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0438\u043C\u0438 \u043D\u043E\u0432\u043E\u0441\u0442\u044F\u043C\u0438 \u0438 \u0441\u0430\u043C\u044B\u043C\u0438 \u0438\u043D\u0442\u0435\u0440\u0435\u0441\u043D\u044B\u043C\u0438 \u0441\u043E\u0431\u044B\u0442\u0438\u044F\u043C\u0438 \u0441\u0430\u043C\u043E\u0439 \u0431\u043E\u043B\u044C\u0448\u043E\u0439 \u0441\u0442\u0440\u0430\u043D\u044B \u043D\u0430 \u0417\u0435\u043C\u043B\u0435.'  # noqa: E501
    publisher = '\u041E\u041E\u041E \u0422\u0438\u044D\u043C\u0442\u0438'
    category = 'newspaper'
    cover_url = u'https://static.themoscowtimes.com/img/share_default.jpg'
    language = 'ru'
    no_stylesheets = False
    remove_javascript = True
    auto_cleanup = False
    oldest_article = 7
    max_articles_per_feed = 50

    remove_tags_before = dict(name='article')

    remove_tags_after = dict(name='div', attrs={'class': 'article__bottom'})

    remove_tags = [
        dict(name='aside'),
        dict(name='footer'),
        dict(name='section', attrs={'class': 'cluster'}),
        dict(name='div', attrs={'class': 'article__tags'}),
        dict(name='div', attrs={'class': 'social'}),
        dict(name='div', attrs={'class': 'related-article__content'})
    ]

    feeds = [(
        '\u041D\u043E\u0432\u043E\u0441\u0442\u0438',
        'https://www.moscowtimes.ru/rss/news'
    ),
             (
                 '\u041C\u043D\u0435\u043D\u0438\u044F',
                 'https://www.moscowtimes.ru/rss/opinion'
             ),
             (
                 '\u041F\u0435\u0440\u0435\u0432\u043E\u0434\u044B Financial Times',
                 'https://www.moscowtimes.ru/rss/ft'
             )]

    def preprocess_html(self, soup):
        for img in soup.findAll('img', attrs={'data-src': True}):
            img['src'] = img['data-src']
        return soup
